/**
 * Created by denh on 16/12/13.
 */
(function(win,doc){
    function change(){
        doc.documentElement.style.fontSize=doc.documentElement.clientWidth/375*23.4375+'px';
    }
    change();
    win.addEventListener('resize',change,false);
})(window,document);

var appContent = new Vue({
    el: '#content',
    data: {
        url_chat : "",
        url_info : "",
        url_videoList : "",
        live_videos : []
    }
});

var appBanner = new Vue({
    el: '#banner',
    data: {
        pic: ""
    }
});

var appTitle = new Vue({
    el: '#title',
    data: {
        title: ""
    }
});

var token = '<?=$this->token?>';
var accout = '<?=$this->accout?>';
getData();

/**
 * 获取数据
 */
function getData() {
    id = common.getParam('id');
    common.serverUrl = '<?=BACK_INTERFACE_BASE_URL?>';
    common.net('CardController_cardDetail', token, id, function(result){
        if(result.code != 0) {
            common.showMsgBox(result.msg);
        } else {
            console.log(result);
            common.setSession('meeting', result);
            apply(result);
        }
    });
}

/**
 * 数据渲染
 * @param result
 */
function apply(result) {
    pic = eval('(' + result.result.pic[0] + ')');

    share_title = result.result.title;
    share_desc = result.result.title;
    share_imgUrl = pic.url;
    share(share_title, share_desc, share_imgUrl);

    if (result.result.liveRadios != undefined) {
        live_videos =  result.result.liveRadios;
        for (i=0; i< live_videos.length; i++) {
            live_videos[i].isBack = false;
            live_videos[i].isLive = false;

            param = {
                token : token,
                account : accout,
                title : live_videos[i].title,
                pic : live_videos[i].pic,
                startTime : live_videos[i].startTime,
                endTime : live_videos[i].endTime,
                chatId : live_videos[i].chatRoom,
                status : live_videos[i].status,
                videoUrl : live_videos[i].videoUrl,
                shareUrl : window.location
            };
            if (live_videos[i].videoHeight) {
                param.videoHeight = live_videos[i].videoHeight;
            }
            if (live_videos[i].videoWidth) {
                param.videoHeight = live_videos[i].videoWidth;
            }

            live_videos[i].htmlUrl = '<?=APPH5_URL?>/html/videolive.html?'+common.urlParam(param);

            if (live_videos[i].status == 1) {
                live_videos[i].statusText = '直播中';
                live_videos[i].isLive = true;
            } else if (live_videos[i].status == 2) {
                live_videos[i].statusText = '视频回放';
                live_videos[i].isBack = true;
            } else {
                live_videos[i].statusText = '';
            }
        }
    } else {
        live_videos = [];
    }

    appBanner.pic = pic.url;
    appContent.url_chat = common.url('meeting', 'chat', 'chatId='+result.result.meetingExt.chatId);
    appContent.url_info = common.url('meeting', 'info', 'id='+id);
    appContent.url_videoList = common.url('meeting', 'videoList', 'id='+id);
    appContent.live_videos = live_videos;
    appTitle.title = result.result.title;
}

/**
 * 微信分享
 * @param share_title
 * @param share_desc
 * @param share_imgUrl
 */
function share(share_title, share_desc, share_imgUrl) {
    wx.config({
        debug: false,
        appId: '<?php echo $this->signPackage["appId"];?>',
        timestamp: '<?php echo $this->signPackage["timestamp"];?>',
        nonceStr: '<?php echo $this->signPackage["nonceStr"];?>',
        signature: '<?php echo $this->signPackage["signature"];?>',
        jsApiList: [
        'onMenuShareAppMessage',
        'onMenuShareTimeline',
        'onMenuShareQQ',
        'onMenuShareWeibo',
        'onMenuShareQZone'
        ]
    });
    links = '';
    weixinShare(share_title, share_desc, links, share_imgUrl);
}


